from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.layout.viewlets.common import ViewletBase
import datetime
import random


class FooterViewlet(ViewletBase):
    render = ViewPageTemplateFile('tp/footer.pt')

    def get_year_copyright(self):
        today = datetime.date.today()
        self.today=today
        return today.year

    def get_random_link(self,category,limit):
        alllinks = self.context.portal_catalog.searchResults(portal_type=('Link'),
                                                        Subject=(category)
                                                        )
        objects=[]
        for link in alllinks:
            objects.append(link)

        random.shuffle(objects)
        return objects[:limit]